local cixiao = fk.CreateSkill {

  name = "joy__cixiao",

  tags = {  },

}



cixiao:addEffect(fk.EventPhaseStart, {
  name = "joy__cixiao",
  anim_type = "control",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(cixiao.name) and player.phase == Player.Start
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local tos = room:askForChoosePlayers(player, table.map(player.room:getOtherPlayers(player), Util.IdMapper), 1, 1, "#joy__cixiao-choose", cixiao.name, true)
    if #tos > 0 then
      event:setCostData(self, {tos[1]})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(event:getCostData(self)[1])
    room:handleAddLoseSkills(to, "joy__panshi", nil, true, false)
    if not player.dead and not to.dead then
      local tar = {}
      for _, p in ipairs(room:getOtherPlayers(to)) do
        if to:inMyAttackRange(p) and not to:isProhibited(p, Fk:cloneCard("slash")) then
          table.insertIfNeed(tar,p.id)
        end
      end
      if #tar <= 0 then return end
      local tos,cards = room:askForChooseCardsAndPlayers(player,1,1,{to.id},1,1, ".|.|.|hand","你可以将一张牌交给本次选择的“义子”，然后令其视为对一名其攻击范围内的角色使用一张【杀】。",cixiao.name,true)
      if #cards > 0 then
        local ta = room:askForChoosePlayers(player,tar,1,1,"选择一名角色，视为 "..Fk:translate(to.general).." 对其使用一张【杀】。",cixiao.name,true,true)
        if #ta > 0 then
          room:obtainCard(to, cards[1], false, fk.ReasonGive,player.id,cixiao.name)
          local t = room:getPlayerById(ta[1])
          if to.dead or t.dead then return end
          if  not to:prohibitUse(Fk:cloneCard("slash")) and not to:isProhibited(t, Fk:cloneCard("slash"))then
            room:useVirtualCard("slash", nil,to,t, cixiao.name, true)
          end
        end
      end
    end
  end,
})

return cixiao